﻿//////////////////////////////
//Update application class.
//////////////////////////////
package org.bbdesign.airbuzz {
	import air.update.ApplicationUpdaterUI;
	import flash.display.*;
	import flash.events.*;
	import flash.filesystem.*;
	import flash.desktop.*;
	import flash.text.*;
	import fl.controls.*;
	//////////////////////////////
	public class Updater extends MovieClip {
		//////////////////////////////
		//Internal class variables.
		//////////////////////////////
		//Instance.
		public var infoText:TextArea;
		public var chk_btn:Button;
		private var appUpdater:ApplicationUpdaterUI;
		//Custom class instances.
		private var _btn_chk_update:Interface = new Interface();
		private var _txt_vercheck:Interface = new Interface();

		//////////////////////////////
		//Constructor.
		//////////////////////////////
		public function Updater() {
			setApplicationNameAndVersion();

			appUpdater = new ApplicationUpdaterUI();
			appUpdater.configurationFile = new File("app:/updateconf/update-config.xml");
			appUpdater.initialize();

			//Check for update button.
			chk_btn = _btn_chk_update.drawButton(Fontlib.FontinBold, 0x260505, 12, 'Update', 20, 540, 100, false);
			addChild(chk_btn);
			chk_btn.addEventListener(MouseEvent.CLICK, checkForUpdate);
		}
		//////////////////////////////

		//////////////////////////////

		//////////////////////////////
		//Private, internal methods.
		//////////////////////////////

		//////////////////////////////

		//////////////////////////////
		//Check for update.
		//////////////////////////////
		private function checkForUpdate(me:MouseEvent):void {
			appUpdater.checkNow();
		}
		//////////////////////////////

		//////////////////////////////
		//Return application name.
		//And version.
		//////////////////////////////
		private function setApplicationNameAndVersion():void {
			var appXML:XML = NativeApplication.nativeApplication.applicationDescriptor;
			var ns:Namespace = appXML.namespace();

			var infotext:TextField = _txt_vercheck.drawTextfield(Fontlib.FontinSansItalic,0,0,0xFFFFFF,20,520,100,17,10,false,0x0A6F9B,false,0x54CCBF,'dynamic','center',false,'infotext', true);
			addChild(infotext);
			infotext.text = "Version: " + appXML.ns::version;
		}
		//////////////////////////////
	}
	//////////////////////////////
}

